package situ.com.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

// 监听系统电量改变的广播
public class SystemReceiver extends BroadcastReceiver {
    private static final String TAG = "SystemReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d(TAG, "onReceive: " + action);
        switch (intent.getAction()) {
            case Intent.ACTION_BATTERY_LOW:
                Toast.makeText(context, "电量过低，请尽快充电！", Toast.LENGTH_LONG).show();
                break;
            case Intent.ACTION_BATTERY_CHANGED:
                Toast.makeText(context, "电量改变！", Toast.LENGTH_LONG).show();
                break;
            case Intent.ACTION_POWER_CONNECTED:
                Toast.makeText(context, "电量充电状态！", Toast.LENGTH_LONG).show();
                break;
            case Intent.ACTION_POWER_DISCONNECTED:
                Toast.makeText(context, "电量断开充电状态！", Toast.LENGTH_LONG).show();
                break;
        }
    }
}
